#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time: 2022/12/22 14:22
# @Author: scg
# @Email: xxx@gmail.com
# @File：utils.py
import xlrd
from pages.login_page import LoginPage
from config.config import USERNAME, PASSWORD
from selenium import webdriver


def get_cookie():
    driver = webdriver.Chrome()
    driver.maximize_window()

    login_page = LoginPage(driver)
    login_page.open()
    login_page.input_name(USERNAME)
    login_page.input_password(PASSWORD)
    login_page.click_login_btn()
    cookies = driver.get_cookies()[0]

    driver.quit()
    cookie = {}
    cookie['name'] = cookies.get('name')
    cookie['value'] = cookies.get('value')
    return cookie


def read_data(file):
    table = xlrd.open_workbook(filename=file).sheet_by_index(0)
    return [tuple(table.row_values(i)) for i in range(1, table.nrows)]

